/*
 * @Author: zi.yang
 * @Date: 2022-02-07 23:06:06
 * @LastEditors: zi.yang
 * @LastEditTime: 2022-02-09 18:16:32
 * @Description: In User Settings Edit
 * @FilePath: \api-generator\app\utils\global.js
 */

'use strict';
const dayjs = require('dayjs');

/**
 * 首字母转换为小写
 * @param { String } text 文本
 * @return { String } 转换后的文本
 */
exports.firstLetterToLowercase = text => {
  const textArr = text.split('');
  const firstText = textArr.shift();
  textArr.unshift(firstText.toLocaleLowerCase());
  return textArr.join('');
};

/**
 * 转换时区
 * @param { Date } date 时间
 * @param { Number } offset 时区 +8
 * @return { Date } 转换后的时区
 */
exports.utcOffset = (date = new Date(), offset = 8) => {
  const _date = dayjs(date).format('YYYY-MM-DD');
  const _time = dayjs(date).format('HH:mm:ss.SSS');
  const offsetHour = dayjs(offset).format('HH:mm');
  return new Date(`${_date}T${_time}+${offsetHour}`);
};
exports.noop = () => {};

